package wykop.analyze;

import wykop.page.WykopComment;

public class ViterbiScore implements ICommentFeature {

	private final Bigrams bigrams;

	public ViterbiScore(final Bigrams bigrams) {
		super();
		this.bigrams = bigrams;
	}

	@Override
	public String forComment(final WykopComment comment) {

		String last = Bigrams.FIRST;
		double score = 0;

		for (final String token : WordBreaker.tokens(comment.getText())) {
			score += Math.log(bigrams.getScores(last, token));
			last = token;
		}

		return String.valueOf(score);

	}

	@Override
	public String name() {
		return "viterbi";
	}

	@Override
	public String type() {
		return "NUMERIC";
	}

}
